package fr.pud.client.view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;

import fr.pud.client.model.Route;

public class RoundPreview extends JScrollPane implements Observer {
    private static final long serialVersionUID = 3137961160852614629L;
    private JList             listStation;
    private JPanel            roundPreview;
    private Route             round;

    public RoundPreview() {
        this.listStation = new JList();
        this.roundPreview = new JPanel();
        this.roundPreview.setPreferredSize(new Dimension((int) Toolkit
                .getDefaultToolkit().getScreenSize().getWidth() / 5,
                (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight()));
        this.roundPreview.setLayout(new BorderLayout());
        this.roundPreview.add(this.listStation, BorderLayout.CENTER);
        this.add(this.roundPreview);
        this.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    }

    public RoundPreview(Route r) {
        this();
        this.round = r;
    }

    public JList getListStation() {
        return this.listStation;
    }

    @Override
    public void update(Observable o, Object arg) {
        this.listStation.setListData(this.round.getStations().toArray());
    }
}
